package com.homer.android.sdk.action.device.common;
import java.net.InetAddress;
import com.homer.android.sdk.command.uart.EspCommandUartGetStatusLocal;
import com.homer.android.sdk.command.uart.IEspCommandUartGetStatusLocal;
import com.homer.android.sdk.devcie.IEspDevice;
import com.homer.android.sdk.devcie.IEspDeviceSSS;
import com.homer.android.sdk.devcie.IEspDeviceUart;
import com.homer.android.sdk.devcie.status.IEspStatusUart;
import com.homer.iot.esptouch.udp.EspDeviceType;

public class EspActionDeviceGetStatusLocal implements IEspActionDeviceGetStatusLocal
{
    
    @Override
    public IEspStatusUart doActionDeviceGetStatusLocal(IEspDevice device)
    {
        EspDeviceType deviceType = device.getDeviceType();
        InetAddress inetAddress = device.getInetAddress();
        String deviceBssid = device.getBssid();
        switch (deviceType)
        {

            case UART:
                IEspCommandUartGetStatusLocal uartCommand = new EspCommandUartGetStatusLocal();
                IEspStatusUart uartStatus =
                		uartCommand.doCommandUartGetStatusLocal(inetAddress, deviceBssid);
                if (uartStatus != null)
                {                   
                    IEspStatusUart statusUart;
                    if (device instanceof IEspDeviceSSS)
                    {
                    	statusUart = (IEspStatusUart)((IEspDeviceSSS)device).getDeviceStatus();
                    }
                    else
                    {
                    	statusUart = ((IEspDeviceUart)device).getStatusUart();
                    }                   
                    statusUart.setIsDefenceOn(uartStatus.isDefenceOn());
                    statusUart.setIsLightOn(uartStatus.isLightOn());
                }
                return uartStatus;
        }
        throw new IllegalArgumentException();
    }
    
}
